package com.ftg.learn.chapter09.io;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * 复制
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/21 下午2:23
 */
public class Cv {

    @SneakyThrows
    public static void main(String[] args) {
        File f1 = new File("/home/kangjx/Desktop/bb.png");
        File f2 = new File("/home/kangjx/Desktop/cc.png");

        if (!f2.exists()) {
            f2.createNewFile();
        }

        // try with resources

        try (
                FileInputStream fis = new FileInputStream(f1);

                FileOutputStream fos = new FileOutputStream(f2);
                //所有的流 前提 可以自动关闭的流
        ) {
            int n = 0;
            while ((n = fis.read()) != -1) {
                fos.write(n);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
